
// import oimo.collision.geometry.Aabb;
// import oimo.m.Vec3;
// import oimo.m.M;

import { Vec3 } from "../../common/Vec3";
import { M } from "../../common/M";
import { Aabb } from "../geometry/Aabb";

/**
 * A proxy is an object that can be added to a broad-phase collision detection algorithm.
 * Users of the collision part of the library can move an axis-aligned bounding box of
 * a proxy through `BroadPhase` class.
 */

export class Proxy {
	_prev: Proxy;
	_next: Proxy;

	// fattened aabb
	_aabbMin: Vec3;
	_aabbMax: Vec3;

	_id: number;

	/**
	 * Extra field that users can use for their own purposes. **Do not modify this property if
	 * you use the physics part of the library**, as the physics part of the library uses this property
	 * for connecting proxies and shapes of rigid bodies.
	 */
	userData: any;


	constructor(userData: any, id: number) {
		this.userData = userData;
		this._id = id;
		this._prev = null;
		this._next = null;
		this._aabbMin = new Vec3();
		this._aabbMax = new Vec3();
	}

	// --- internal ---
	public _setAabb(aabb: Aabb): void {
		M.vec3_assign(this._aabbMin, aabb._min);
		M.vec3_assign(this._aabbMax, aabb._max);
	}

	// --- public ---

	/**
	 * Returns the unique id of the proxy.
	 */
	public getId(): number {
		return this._id;
	}

	/**
	 * Returns the fat AABB of the proxy.
	 */
	public getFatAabb(): Aabb {
		var aabb: Aabb = new Aabb();
		M.vec3_assign(aabb._min, this._aabbMin);
		M.vec3_assign(aabb._max, this._aabbMax);
		return aabb;
	}

	/**
	 * Sets `aabb` to the fat AABB of the proxy.
	 *
	 * This does not create a new instance of `Aabb`.
	 */
	public getFatAabbTo(aabb: Aabb): void {
		M.vec3_assign(aabb._min, this._aabbMin);
		M.vec3_assign(aabb._max, this._aabbMax);
	}
}
